package com.cn.crmsystem.controller.businessController;

import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.pojo.Returned;
import com.cn.crmsystem.service.businessService.ReturnedService;
import io.swagger.annotations.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Api(value = "回款",tags ="回款接口API" )
public class AllReturnedController {
    @Autowired
    private ReturnedService returnedService;

    @RequestMapping(value = "/selectReturnedAll", method = RequestMethod.POST)
    @ApiOperation(value = "查询所有回款接口", notes = "业务员管理员操作", httpMethod = "POST", response = ResultJson.class)
    //筛选查询条件
    @ApiImplicitParams({
            @ApiImplicitParam(name = "return_state", value = "回款状态", paramType = "query", dataType = "returned", required = false),
            @ApiImplicitParam(name = "contract_id", value = "合同编号", paramType = "query", dataType = "returned", required = false),
            @ApiImplicitParam(name = "creation_time", value = "创建时间", paramType = "query", dataType = "returned", required = false),
            @ApiImplicitParam(name = "create_id", value = "创建人", paramType = "query", dataType = "returned", required = false)
    })
    public ResultJson selectReturnedAll(@RequestBody
                                        @ApiParam(name = "map", value = "{contract_id 合同编号(int)," +
                                                "return_number 回款编号(String), " + "actual_income 结算金额（Double）," +
                                                "balance 尾款（double）," +
                                                "create_id 创建人id (int)" +
                                                "creation_time 创建时间 (date)" +
                                                "return_state 回款状态（0：收款完成，1：催缴完成，2:代缴）" +
                                                "}") Map map) {
        return returnedService.selectReturnedAll(map);
    }

    /**
     * 新增回款
     *
     * @param returned
     * @return
     */
    @RequestMapping(value = "/addReturned", method = RequestMethod.POST)
    @ApiOperation(value = "新增回款接口", notes = "业务员管理员新增", httpMethod = "POST", response = ResultJson.class)
    @ApiImplicitParam(name = "return_number", value = "回款编号", required = false, dataType = "returned", paramType = "query")
    public ResultJson addReturned(@RequestBody  Returned returned) {
        Login login = (Login) SecurityUtils.getSubject().getPrincipal();

//        Login login = new Login();
//        login.setUser_id(1);
        System.out.println(login);
        System.out.println("新增回款");
        return returnedService.addReturned(returned,login);
    }

    /**
     * 根据ID修改回款
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/updateReturned", method = RequestMethod.POST)
    @ApiOperation(value = "修改回款接口", notes = "管理层修改", httpMethod = "POST", response = ResultJson.class)
    @ApiImplicitParam(name = "id", value = "回款编号", required = true, dataType = "Integer", paramType = "query")
    public ResultJson updateReturned(@ApiParam(name = "returned", value = "修改回款") Integer id) {
        return returnedService.updateReturned(id);
    }

    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteReturned", method = RequestMethod.POST)
    @ApiOperation(value = "删除回款（修改状态）接口", notes = "管理层修改", httpMethod = "POST", response = ResultJson.class)
    @ApiImplicitParam(name = "id", value = "回款编号", required = true, dataType = "Integer", paramType = "query")
    public ResultJson deleteReturned(@RequestParam  Integer id) {
        return returnedService.deleteReturned(id);
    }
}
